﻿Public Class frmRemiseCHQ
    Private szSQL As String
    Private rs As ADODB.Recordset

    Private Sub frmRemiseCHQ_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        TE_DATE.Value = Today
        Call InitVersements(0)

    End Sub

    Private Sub InitVersements(ByVal ix As Integer)

        Dim nb As Integer = 0
        Dim total As Decimal = 0

        ' effacer la listview
        LV_REMISE.Items.Clear()

        ' lire toutes les réglements de la facture
        szSQL = "CALL spGET_LIV_BNQ('byDate','" & gSocieteCode & "',0,0,'" & Format(TE_DATE.Value, "yyyy-MM-dd") & "','')"
        GetRecordset(ctDSN_DEVFAC, szSQL, rs)
        Do While Not rs.EOF
            LV_REMISE.Items.Add(rs.Fields("date").Value)
            LV_REMISE.Items(nb).SubItems.Add(LibByCode("P_MODEREG", rs.Fields("modereg").Value))
            LV_REMISE.Items(nb).SubItems.Add(rs.Fields("ets").Value)
            LV_REMISE.Items(nb).SubItems.Add(rs.Fields("jst").Value)
            LV_REMISE.Items(nb).SubItems.Add(rs.Fields("montantregl").Value)
            LV_REMISE.Items(nb).SubItems.Add(rs.Fields("jnl").Value)
            LV_REMISE.Items(nb).SubItems.Add(Format(rs.Fields("cod_bnq").Value, "000000"))
            total += rs.Fields("montantregl").Value
            rs.MoveNext()
            nb = nb + 1
        Loop
        rs.Close()

        TE_NOMBRE.Text = nb & " chèque(s)"
        TE_TOTAL.Text = total.ToString("C")

        ' restaurer la position du curseur avant le init
        setIndice(ix, LV_REMISE)

    End Sub

    Private Sub TE_DATE_ValueChanged(sender As Object, e As System.EventArgs) Handles TE_DATE.ValueChanged
        Call InitVersements(0)
    End Sub

    Private Sub BO_IMPRIMER_Click(sender As System.Object, e As System.EventArgs) Handles BO_IMPRIMER.Click

        gDate_debut = TE_DATE.Value
        gDate_fin = TE_DATE.Value
        frmViewReport.pNomEtat = "BordxRemise.rpt"
        frmViewReport.pParamRPT = ""
        frmViewReport.ShowDialog()

    End Sub
End Class